package cn.wolfcode.config;

import cn.wolfcode.interceptor.BlackListInterceptor;
import cn.wolfcode.interceptor.BrushProofInterceptor;
import cn.wolfcode.interceptor.CheckLoginInterceptor;
import cn.wolfcode.interceptor.SignInterceptor;
import cn.wolfcode.resolver.UserinfoArgumentResover;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.List;

@Configuration
public class WebConfig implements WebMvcConfigurer {

    @Autowired
    private CheckLoginInterceptor checkLoginInterceptor;

    @Autowired
    private SignInterceptor signInterceptor;

    @Autowired
    private BlackListInterceptor blackListInterceptor;
    @Autowired
    private BrushProofInterceptor brushProofInterceptor;
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(blackListInterceptor).addPathPatterns("/**").order(Integer.MIN_VALUE);
        registry.addInterceptor(checkLoginInterceptor).addPathPatterns("/**").excludePathPatterns("/users/*").excludePathPatterns("/getTime");
        // 防刷
        registry.addInterceptor(brushProofInterceptor).addPathPatterns("/**").excludePathPatterns("/getTime");
        // 防篡改
        registry.addInterceptor(signInterceptor).addPathPatterns("/**").excludePathPatterns("/getTime");

    }

    @Autowired
    UserinfoArgumentResover userinfoArgumentResover;

    @Override
    public void addArgumentResolvers(List<HandlerMethodArgumentResolver> resolvers) {
        resolvers.add(userinfoArgumentResover);
    }




}
